#ifndef MYSQL_H
#define MYSQL_H
#include <vector>
#include <mysql_connection.h>
#include <mysql_driver.h>
#include <statement.h>
#include <prepared_statement.h>
#include <memory>


class mysql
{
public:
    mysql();
    //连接数据库
    void connectToSql(const std::string address,const std::string user,
                      const std::string password,const std::string dbname);
    //无参数，无结果，一般命令
    void executeVoid(std::string query);
    //无参数，有结果，一般命令
    sql::ResultSet* execute(std::string query);
    //多参数，无结果，一般命令
    void executeVoid(std::string query,std::vector<std::string>& args);
    //多参数，有结果，预编译命令
    sql::ResultSet *preExecute(std::string query,std::vector<std::string>& args);
    sql::ResultSet *preExecute(std::string query,std::string& arg1);
    sql::ResultSet *preExecute(std::string query,std::string& arg1,std::string& arg2);

    //无参数，无结果，预编译命令
    void preExecuteVoid(std::string query);
    //一参数，无结果，预编译命令
    void preExecuteVoid(std::string query,std::string& arg1);
    //二参数，无结果，预编译命令
    void preExecuteVoid(std::string query,std::string& arg1,std::string& arg2);
    //多参数，无结果，预编译命令
    void preExecuteVoid(std::string query,std::vector<std::string>& args);

    void startTransaction();
    void commit();
    void disconnect();
    bool resIsEmpty();
    void freeRes();
    void setCurDB(std::string db_name);
    void resetResPos();
    void setResPos(unsigned int pos);
private:
    void checkRes();
private:
    static sql::Driver* driver;
    sql::Connection* conn;
    sql::Statement* stmt;
    sql::PreparedStatement* pre_stmt;
    sql::ResultSet* res;
    bool res_is_empty;
};

#endif // MYSQL_H
